/*
 * Copyright (c) 2009 Roman Savelyev
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "conuiterminal.h"
#include <ecom.h>
#include "conuitermlogger.h"

EXPORT_C CConUiTerminal* CConUiTerminal::NewL(const TDesC8& aTerminalType, MConUiTerminalObserver& aObserver)
    {
    FL(_L("CConUiTerminal::NewL"));
    FLTRACEVALUE(aTerminalType);
    TEComResolverParams params;
    params.SetDataType(aTerminalType);
    TAny* ptr = REComSession::CreateImplementationL(
        KConTerminalInterfaceUid,
        _FOFF(CConUiTerminal, iDtor_ID_Key),
        params
        );
    CConUiTerminal* instance = reinterpret_cast<CConUiTerminal*>(ptr);
    instance->iObserver = &aObserver;
    }

EXPORT_C CConUiTerminal::~CConUiTerminal()
    {
    FL(_L("CConUiTerminal::~CConUiTerminal"));
    REComSession::DestroyedImplementation(iDtor_ID_Key);
    }

EXPORT_C TSize CConUiTerminal::SurfaceSize()
    {
    TSize size;
    TInt err = DoSurfaceSize(size);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::SetBackground(ConUiDef::TColor aColor)
    {
    TInt err = DoSetBackground(aColor);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::SetForeground(ConUiDef::TColor aColor)
    {
    TInt err = DoSetForeground(aColor);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::SetBold(TBool aBold)
    {
    TInt err = DoSetBold(aBold);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::SetInverseVideo(TBool aInverseVideo)
    {
    TInt err = DoSetInverseVideo(aInverseVideo);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::SetPos(const TPoint& aPoint)
    {
    TInt err = DoSetPos(aPoint);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::HideCursor()
    {
    TInt err = DoHideCursor();
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::ShowCursor()
    {
    TInt err = DoShowCursor();
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::Write(const TDesC& aOutput)
    {
    TInt err = DoWrite(aOutput);
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::ClearSurface()
    {
    TInt err = DoClearSurface();
    __ASSERT_ALWAYS(KErrNone == err, iObserver->HandleTerminalError(err));
    }

EXPORT_C void CConUiTerminal::ReadKey(TConsoleKey& aKey, TRequestStatus& aStatus)
    {
    DoReadKey(aKey, aStatus);
    }

EXPORT_C void CConUiTerminal::ReadKeyCancel()
    {
    DoReadKeyCancel();
    }
